package cn.itcast.order.controller;

import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.order.OrderReqDTO;
import cn.itcast.hmall.pojo.order.Order;
import cn.itcast.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderReqDTO
     * @return
     */
    @PostMapping("/order")
    public String addOrder(@RequestBody OrderReqDTO orderReqDTO){

     return orderService.addOrder(orderReqDTO);
    }


    /**
     * 根据订单id查询订单
     * @param orderId  订单id
     * @return
     */

    @GetMapping("/order/{orderId}")
    public Order queryOrderById(@PathVariable("orderId") Long orderId ){

        return orderService.getById(orderId);
    }

    /**
     *订单支付
     * @param
     * @return
     */
    @PutMapping("/pay/{orderId}")
    public ResultDTO payOrder(@PathVariable("orderId") Long orderId,
                              @RequestBody Map<String,String> key){
        return  orderService.payOrder(orderId,key);
    }
}
